package edu.gmu.atelier;

import java.util.List;

/**
 * Set of vectors with vector combination and scalar multiplication operations.
 * @author James H. Pope
 */
public class RealVectorFactory implements VectorFactory
{
    public static final RealVectorFactory INSTANCE = 
            new RealVectorFactory();
    
    public RealVectorFactory()
    {
        
    }
    
    //------------------------------------------------------------------------//
    // Factory methods
    //------------------------------------------------------------------------//
    
    public Vector makeVector( int n )
    {
        double[] elems = new double[n];
        for (int i = 0; i < elems.length; i++)
        {
            elems[i] = 0.0;
        }
        return new RealVector(elems);
    }
    
    public Matrix makeIdentity( int n )
    {
        java.util.List<Vector> b = new java.util.ArrayList<Vector>();
        for (int c = 0; c < n; c++)
        {
            double[] elems = new double[n];
            elems[c] = 1.0;
            b.add(c, new RealVector(elems) );
        }
        return new Matrix(b, this);
    }
    
    public Matrix makeIdentity( int m, int n )
    {
        java.util.List<Vector> b = new java.util.ArrayList<Vector>();
        int min = Math.min( m, n );
        for (int c = 0; c < min; c++)
        {
            double[] elems = new double[m];
            elems[c] = 1.0;
            b.add(c, new RealVector(elems) );
        }
        return new Matrix(b, this);
    }
    
    /**
     * Makes a new matrix from data array in row-major order.
     * @param data
     * @return 
     */
    public Matrix makeMatrix(double[][] data)
    {
        java.util.List<Vector> b = new java.util.ArrayList<Vector>();
        for (int c = 0; c < data[0].length; c++)
        {
            double[] comps = new double[data.length];
            for (int r = 0; r < comps.length; r++)
            {
                comps[r] = data[r][c];
            }
            b.add(c, new RealVector(comps) );
        }
        //return b;
        return new Matrix(b, INSTANCE);
    }

    /**
     * Makes a new vector from data.
     * @param data (column for vector)
     * @return 
     */
    public RealVector makeVector(double[] data)
    {
        return new RealVector(data);
    }
    
    /**
     * Makes a new mutable zero element.
     * @return 
     */
    public Element makeZero( )
    {
        return RealElement.ZERO.copy();
    }
    
    /**
     * Makes a new mutable one element.
     * @return 
     */
    public Element makeOne( )
    {
        return RealElement.ONE.copy();
    }
}
